home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 16 / Mac Magazin and MacEasy Magazine CD - Issue 16.iso / System / Kontrollleisten-Module / Trash It! 3.5 ƒ / Only for the brave… next >
Text File  |  1995-11-04  |  3KB  |  62 lines

  1. How to hack drag-aware text editors to allow you to delete text dropped over Trash It!
  2. by Ammon Skidmore <mailto:ammon@cs.byu.edu>, November 3, 1995
  3.  
  4. The Background:
  5. ---------------
  6. Apple's drag manager sample code does an overkill check to see if the drag was dropped on the Finder's trash can.  One of its criteria is that the drag must leave the sender application:
  7.  
  8. GetDragAttributes(theDrag, &attributes);
  9. if (!(attributes & dragInsideSenderApplication)) {
  10.   GetDropLocation(theDrag, &dropLocation);
  11.   ...
  12. }
  13.  
  14. While this is ok for normal use, it breaks when drags enter a floating window.  So to fix this situation, I could either
  15. a) patch the drag manager like crazy (no!)
  16. b) figure out the undocumented format of the DragReference so that we can manually turn off the dragInsideSenderApplication flag in our code (no!)
  17. c) patch each offending application (yes!)
  18.  
  19.  
  20. The Hack:
  21. ---------
  22. We will operate, for example, on SimpleText 1.2.  Here is the code piece of interest:
  23.  Disassembling from 00E78222
  24.   'CODE 0006 1144 Text'
  25.      +030E2 00E78222   MOVEQ      #$19,D0                                 | 7019
  26.      +030E4 00E78224   _GetDragAttributes                    ; 00088912   | ABED
  27.      +030E6 00E78226   MOVEQ      #$02,D0                                 | 7002
  28.      +030E8 00E78228   AND.L      -$0008(A6),D0                           | C0AE FFF8
  29.      +030EC 00E7822C   ADDQ.W     #$2,A7                                  | 544F
  30.      +030EE 00E7822E   BNE        'CODE 0006 11… Text'+0317A ; 00E782BA   | 6600 008A
  31.      +030F2 00E78232   SUBQ.L     #$2,A7                                  | 558F
  32.      +030F4 00E78234   MOVE.L     -$0014(A6),-(A7)                        | 2F2E FFEC
  33.      +030F8 00E78238   PEA        -$0010(A6)                              | 486E FFF0
  34.      +030FC 00E7823C   MOVEQ      #$17,D0                                 | 7017
  35.      +030FE 00E7823E   _GetDropLocation                      ; 00088912   | ABED
  36.      +03100 00E78240   SUBQ.L     #$2,A7                                  | 558F
  37.      +03102 00E78242   MOVE.L     -$0014(A6),-(A7)                        | 2F2E FFEC
  38.  
  39. Note the number 2 moved into D0 after GetDragAttributes is called.  This is the constant dragInsideSenderApplication.  All that the hack consists of is changing this number to zero, so that the bit-wise AND always returns zero.
  40.  
  41. Open a copy of your favorite drag-aware text editor in ResEdit, Resorcerer, or some sort of utility that can find hex strings in the resource fork of files.  Tip: Resorcerer is _very_ nice for this.
  42.  
  43. If this hack was only for SimpleText, then we would just search for '7019ABED7002' and change it to '7019ABED7000'.  But, the program Stickies shrinks the stack after it calls _GetDragAttributes, so the following is necessary:
  44.  
  45. a) Open a CODE resource (for SimpleText it is id 6, 'Text').
  46. b) Search for: '7019ABED'.
  47. c) See if there are any nearby occurrences of '7002'.
  48. d) If not, goto step b until an occurrence is found, or the end of the resource is reached in which case you should open the next CODE resource and try again.
  49. e) Change '7002' to '7000'.
  50.  
  51. That's it!
  52.  
  53. This hack has so far been tested successfully on:
  54. SimpleText       - modify CODE id 6, 'Text'
  55. Stickies         - modify CODE id 7
  56. Tex-Edit Plus    - modify CODE id 1, 'Main'
  57. (can you add any more?)
  58.  
  59. Also, this hack is not necessary for the following programs:
  60. NewsWatcher
  61.  
  62.